<!--
	This file is part of ELCube.
	ELCube is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	ELCube is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.
	You should have received a copy of the GNU Affero General Public License
	along with ELCube.  If not, see <https://www.gnu.org/licenses/>.
-->
<template>
    <nk-card>
        <vxe-table
                ref="xTable"
                row-key
                auto-resize
                keep-source
                resizable
                size="mini"
                border=inner
                :expand-config="{}"
                :data="list">
            <vxe-column type="expand" title="KEY" field="key" width="30%" >
                <template #default="{ row, rowIndex }">
                    <span>{{ row.key }}</span>
                </template>
                <template #content="{ row, rowIndex }">
                    <div style="padding: 5px 5px 10px;">
                        <span>原始数据：</span>
                        <json-viewer
                                v-if="row.response"
                                :value="row.response"
                                :expand-depth=5
                                theme="jv-light"
                                copyable
                                boxed
                                sort ></json-viewer>
                        <span v-if="row.mapping" style="margin-top: 5px;">映射结果：</span>
                        <json-viewer
                                v-if="row.mapping"
                                :value="row.mapping"
                                :expand-depth=5
                                theme="jv-light"
                                copyable
                                boxed
                                sort ></json-viewer>
                    </div>
                </template>
            </vxe-column>
            <vxe-column field="desc"         title="描述" ></vxe-column>
        </vxe-table>

        <div v-if="data && data.result" style="text-align: right;margin-top: 5px;padding-right: 5px;">
            <a v-if="!showResult" @click="json=data.result" >返回内容</a>
            <a v-else             @click="json=undefined"   >收起返回内容</a>
        </div>
        <json-viewer
                v-if="showResult && data && data.result"
                :value="data.result"
                :expand-depth=5
                theme="jv-light"
                copyable
                boxed
                sort ></json-viewer>
    </nk-card>
</template>

<script>
    import Mixin from "Mixin";

    export default {
        mixins:[new Mixin()],
        data(){
            return {
                showResult:false
            }
        },
        computed:{
            list(){
                return this.data && this.data.services && this.def.services && this.def.services.map(service=>{
                    const data = this.data.services[service.key];
                    if(data){
                        return Object.assign({},data,service);
                    }
                    return undefined
                }).filter(service=>service);
            }
        }
    }
</script>

<style scoped>

</style>